<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8 " /> 
<title>回访数据</title> 
<link rel="stylesheet" type="text/css" href="__PUBLIC__/ui/js/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="__PUBLIC__/ui/js/themes/icon.css" />
<style type="text/css">
#fm{margin:0;padding:10px 30px;}
.ftitle{font-size:14px;font-weight:bold;color:#666;padding:5px 0;margin-bottom:10px;border-bottom:1px solid #ccc;}
.fitem{margin-bottom:5px;}
.fitem label{display:inline-block;width:80px;}
.panel{margin:0px auto;}
.role_line{margin-bottom:5px;}
.role_line:hover{background:#e91;}
.role_line label{display:inline-block;width:270px;}
#dd{padding-top:8px;}
</style>
<script type="text/javascript" src="__PUBLIC__/ui/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/ui/js/jquery.easyui.min.js"></script>
<script type="text/javascript">
var url;
//增加节点
function newRole(){
$('#dlg').dialog('open').dialog('setTitle','增加节点');
	$('#fm').form('clear');
	url = '__URL__/role_add';
}
//修改节点
function editRole(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$('#dlg').dialog('open').dialog('setTitle','节点修改');
		$('#fm').form('load',row);
		url = '__URL__/role_update/id/'+row.id;
	}
}
//保存节点
function saveUser(fm){
	$('#'+fm).form('submit',{
		url: url,
		onSubmit: function(){
			return $(this).form('validate');
		},
		success: function(result){
			var result = eval('('+result+')');
			if (result.success){
				if(fm=='fm'){dlg='#dlg'}else{dlg='#sysTxt'}//检查当前的操作
				$(dlg).dialog('close');		// close the dialog
				$('#dlgUser').dialog('close'); //close the #dlgUser
				$('#dg').datagrid('reload');	// reload the user data
				$('#dg2').datagrid('reload');	// reload the user data
				$.messager.show({
					title: '成功',
					msg: '操作数据成功'
				});
			} else {
				$.messager.show({
					title: '错误',
					msg: result.msg
				});
			}
		}
	});
}
//删除节点
function removeRole(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$.messager.confirm('删除节点','您确定要删除此节点吗？',function(r){
			if (r){
				$.post('__URL__/role_del',{id:row.id},function(result){
					if (result.success){
						$('#dg').datagrid('reload');	// reload the user data
					} else {
						$.messager.show({	// show error message
							title: '错误',
							msg: result.msg
						});
					}
				},'json');
			}
		});
	}
}

//权限设定
function sysRole(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		//先清除权限设定的checked
		$.each($(".checked"),function(k,v){
			v.checked=false;	
		});
		//这里是给选中的用户权限勾选上
		$.ajax({
			url:"__URL__/RoleCheckbox/roleid/"+row.id,
			type:"GET",
			dataType:"json",
			success: function(json){
				if(json){
					$.each(json,function(k,v){
						$('#'+v.toString()).attr("checked","true");
					})	
				}
				console.debug(json);
			}
				
		});
		$('#sysTxt').dialog('open').dialog('setTitle','权限设定');
		$('#sys').form('load',row);
		url = '__URL__/sysRole/roleid/'+row.id;
	}
}

//用户组管理设定
function group(){
	var row = $('#dg').datagrid('getSelected');
	if (row){
		$('#dd').dialog({
			title:'组用户',
			width:1000,
			height:450,
			closed: false,
			cache: false,   
			modal: true,
			href:'__URL__/group/roleid/'+row.id
		}); 
	}
}

//增加用户
function addUser(){
$('#dlgUser').dialog('open').dialog('setTitle','增加用户');
	$('#fmUser').form('clear');
	url = '__URL__/user_add';
}

//修改用户
function editUser(){
	var row = $('#dg2').datagrid('getSelected');
	if (row){
		$('#dlgUser').dialog('open').dialog('setTitle','用户修改');
		$('#fmUser').form('load',row);
		url = '__URL__/user_update/id/'+row.id;
	}
}
</script>

<body>
<div id="dd"></div>
	<table align="center" class="easyui-datagrid" id="dg" style="width:1000px;height:450px; text-align:center" title="用户组管理"
			url="__GROUP__/User/role_list"
			toolbar="#toolbar" pagination="true"
			rownumbers="true" fitColumns="true" singleSelect="true">
		<thead>
			<tr>
				<th field="id" width="50">用户组ID</th>
				<th field="name" width="50">用户组名</th>
			</tr>
		</thead>
	</table>
	<div id="toolbar">
		<a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newRole()">增加</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editRole()">修改</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="sysRole()">权限设定</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="group()">组用户</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="removeRole()">删除</a>
	</div>
	
	<div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons">
		<div class="ftitle">不同的用户组拥有不同的权限</div>
		<form id="fm" method="post" novalidate>
			<div class="fitem">
				<label>用户组名:</label>
				<input name="name" class="easyui-validatebox" required>
			</div>
		</form>
	</div>
	<div id="dlg-buttons">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser('fm')">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
	</div>

<!--节点管理-->    
    <div id="sysTxt" class="easyui-dialog" style="width:950px;height:550px;padding:10px 20px"
			closed="true" buttons="#dlg-buttons2">
		<div class="ftitle">用户权限设定</div>
		<form id="sys" method="post" novalidate>
        <div class="role_line" style="font-weight:bold"><label>操作名</label><label>操作路径</label><label>选择</label></div>
        <volist name="node" id="vo">
		  <div class="role_line">
				<label>{$vo.name}</label><label>{$vo.action}</label>
		    <input type="checkbox" name="purviews[]" id="{$vo.id}" value="{$vo.id}" class="checked" />
			</div>
         </volist>
		</form>
	</div>
    <div id="dlg-buttons2">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser('sys')">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#sysTxt').dialog('close')">关闭</a>
	</div>
    
 <!--用户增加-->
 <div id="dlgUser" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
			closed="true" buttons="#dlg-user">
		<div class="ftitle">不同的用户组拥有不同的权限</div>
		<form id="fmUser" method="post" novalidate>
			<div class="fitem">
				<label>登陆ID:</label>
				<input name="name" class="easyui-validatebox" required>
			</div>
			<div class="fitem">
				<label>真实姓名:</label>
				<input name="tname" class="easyui-validatebox" required>
			</div>
			<div class="fitem">
				<label>用户密码:</label>
				<input name="pwd" class="easyui-validatebox" required>
			</div>
			<div class="fitem">
				<label>用户邮箱:</label>
				<input name="email" class="easyui-validatebox" required>
			</div>
			<div class="fitem">
				<label>用户组:</label>
				<input name="usertypeid" class="easyui-validatebox" required>
			</div>
		</form>
	</div> 
    <div id="dlg-user">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveUser('fmUser')">保存</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgUser').dialog('close')">关闭</a>
	</div>  
</body>
</html>